Bug 382291 – Automatically dim the combobox when the model is empty
authorMatthias Clasen <mclasen@redhat.com>
Mon, 4 Aug 2008 23:40:36 +0000 (23:40 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 4 Aug 2008 23:40:36 +0000 (23:40 +0000)
2008-08-04  Matthias Clasen  <mclasen@redhat.com>

        Bug 382291 – Automatically dim the combobox when the model is empty

        * gtk/gtk.symbols:
        * gtkcombobox.[hc]: Add a GtkComboBox::button-sensitivity
        property with getter and setter to control the sensitity of
        empty combo boxes. Patch by Carlos Garnacho, Sven Herzberg,
        Christian Dywan and others.

        * README.in: Add a note about automatic combobox sensitivity.

svn path=/trunk/; revision=20997

ChangeLog
README.in
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtkcombobox.c
gtk/gtkcombobox.h

index 0ec0758c235622d3c959879a9e82914beef2c1ba..6f5f0e60efc15bb852323226a797c6d06c5ce10b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,13 +1,13 @@
-2008-08-05  Tor Lillqvist  <tml@novell.com>
-
-       * gtk/updateiconcache.c (write_bucket): Enclose ?: expression
-       with parens so cast covers all of it.
-
 2008-08-04  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtksettings.c: Improve a setting nick: 'aureal' is not really
        a word, use 'audible' instead.
 
+2008-08-05  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/updateiconcache.c (write_bucket): Enclose ?: expression
+       with parens so cast covers all of it.
+
 2008-08-04  Matthias Clasen  <mclasen@redhat.com>
 
        Bug 382291 – Automatically dim the combobox when the model is empty
index 908358f2155614e763e16c4a1a039424cedd96c9..71b653820658d7a308d679c261be6790b39a1ff5 100644 (file)
--- a/README.in
+++ b/README.in
@@ -42,6 +42,12 @@ Release notes for 2.14
   the GtkFileSystem interface is no longer available, nor the filechooser
   will load any GtkFileSystem implementation.
 
+* GtkComboBox now renders the popdown button insensitive when
+  the model is empty. Applications which want to populate the list
+  only before displaying it can set gtk_combo_box_set_button_sensitivity
+  to GTK_SENSITIVITY_ON, so that the button is always sensitive or
+  GTK_SENSITIVITY_OFF to make it insensitive respectively.
+
 Release notes for 2.12
 ======================
 
index 2cb03367d40847752fd8cf393aacffe8b5b2ae96..883876087216eee947f1aef0f94a6f35ee924706 100644 (file)
@@ -1,3 +1,7 @@
+2008-08-04  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk-sections.txt: Add new functions
+
 2008-08-02  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtk-sections.txt: Add new functions
index 83ea0dd21d7f1d30d299dc855668984a0d8d9885..21571a75195c7c8d3e56543c29d43983b02f157c 100644 (file)
@@ -895,6 +895,8 @@ gtk_combo_box_set_title
 gtk_combo_box_get_title
 gtk_combo_box_set_focus_on_click
 gtk_combo_box_get_focus_on_click
+gtk_combo_box_set_button_sensitivity
+gtk_combo_box_get_button_sensitivity
 <SUBSECTION Standard>
 GTK_TYPE_COMBO_BOX
 GTK_COMBO_BOX
index 0c4a436b8d24ffe39aafa3b4f32437f61f4feac8..acb5286c2770530ffcc7d2dc38deb0b349ef8b63 100644 (file)
@@ -853,6 +853,7 @@ gtk_combo_box_get_model
 gtk_combo_box_get_popup_accessible
 gtk_combo_box_get_row_separator_func
 gtk_combo_box_get_row_span_column
+gtk_combo_box_get_button_sensitivity
 gtk_combo_box_get_title
 gtk_combo_box_get_type G_GNUC_CONST
 gtk_combo_box_get_wrap_width
@@ -872,6 +873,7 @@ gtk_combo_box_set_focus_on_click
 gtk_combo_box_set_model
 gtk_combo_box_set_row_separator_func
 gtk_combo_box_set_row_span_column
+gtk_combo_box_set_button_sensitivity
 gtk_combo_box_set_title
 gtk_combo_box_set_wrap_width
 #endif
index 14a6bec9df9a55caaf5885c743ee503aa4f676f8..0a081d11a54285a05f369d7e0661c9083c9af17d 100644 (file)
@@ -120,6 +120,7 @@ struct _GtkComboBoxPrivate
   guint editing_canceled : 1;
   guint auto_scroll : 1;
   guint focus_on_click : 1;
+  guint button_sensitivity : 2;
 
   GtkTreeViewRowSeparatorFunc row_separator_func;
   gpointer                    row_separator_data;
@@ -201,7 +202,8 @@ enum {
   PROP_TEAROFF_TITLE,
   PROP_HAS_FRAME,
   PROP_FOCUS_ON_CLICK,
-  PROP_POPUP_SHOWN
+  PROP_POPUP_SHOWN,
+  PROP_BUTTON_SENSITIVITY
 };
 
 static guint combo_box_signals[LAST_SIGNAL] = {0,};
@@ -822,6 +824,24 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
                                                          FALSE,
                                                          GTK_PARAM_READABLE));
 
+
+   /**
+    * GtkComboBox:button-sensitivity:
+    *
+    * Whether the dropdown button is sensitive when
+    * the model is empty.
+    *
+    * Since: 2.14
+    */
+   g_object_class_install_property (object_class,
+                                    PROP_BUTTON_SENSITIVITY,
+                                    g_param_spec_enum ("button-sensitivity",
+                                                       P_("Button Sensitivity"),
+                                                       P_("Whether the dropdown button is sensitive when the model is empty"),
+                                                       GTK_TYPE_SENSITIVITY_TYPE,
+                                                       GTK_SENSITIVITY_AUTO,
+                                                       GTK_PARAM_READWRITE));
+
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_boolean ("appears-as-list",
                                                                  P_("Appears as list"),
@@ -919,6 +939,7 @@ gtk_combo_box_init (GtkComboBox *combo_box)
   priv->editing_canceled = FALSE;
   priv->auto_scroll = FALSE;
   priv->focus_on_click = TRUE;
+  priv->button_sensitivity = GTK_SENSITIVITY_AUTO;
 
   combo_box->priv = priv;
 
@@ -979,6 +1000,11 @@ gtk_combo_box_set_property (GObject      *object,
           gtk_combo_box_popdown (combo_box);
         break;
 
+      case PROP_BUTTON_SENSITIVITY:
+        gtk_combo_box_set_button_sensitivity (combo_box,
+                                              g_value_get_enum (value));
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -1035,6 +1061,10 @@ gtk_combo_box_get_property (GObject    *object,
         g_value_set_boolean (value, combo_box->priv->popup_shown);
         break;
 
+      case PROP_BUTTON_SENSITIVITY:
+        g_value_set_enum (value, combo_box->priv->button_sensitivity);
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -3121,6 +3151,32 @@ gtk_combo_box_menu_item_activate (GtkWidget *item,
   combo_box->priv->editing_canceled = FALSE;
 }
 
+static void
+gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
+{
+  GtkTreeIter iter;
+  gboolean sensitive = TRUE; /* fool code checkers */
+
+  switch (combo_box->priv->button_sensitivity)
+    {
+      case GTK_SENSITIVITY_ON:
+        sensitive = TRUE;
+        break;
+      case GTK_SENSITIVITY_OFF:
+        sensitive = FALSE;
+        break;
+      case GTK_SENSITIVITY_AUTO:
+        sensitive = combo_box->priv->model &&
+                    gtk_tree_model_get_iter_first (combo_box->priv->model, &iter);
+        break;
+      default:
+        g_assert_not_reached ();
+        break;
+    }
+
+  gtk_widget_set_sensitive (combo_box->priv->button, sensitive);
+}
+
 static void
 gtk_combo_box_model_row_inserted (GtkTreeModel     *model,
                                  GtkTreePath      *path,
@@ -3133,6 +3189,8 @@ gtk_combo_box_model_row_inserted (GtkTreeModel     *model,
     gtk_combo_box_list_popup_resize (combo_box);
   else
     gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
+
+  gtk_combo_box_update_sensitivity (combo_box);
 }
 
 static void
@@ -3154,6 +3212,8 @@ gtk_combo_box_model_row_deleted (GtkTreeModel     *model,
     gtk_combo_box_list_popup_resize (combo_box);
   else
     gtk_combo_box_menu_row_deleted (model, path, user_data);  
+
+  gtk_combo_box_update_sensitivity (combo_box);
 }
 
 static void
@@ -4945,6 +5005,8 @@ gtk_combo_box_set_model (GtkComboBox  *combo_box,
                              combo_box->priv->model);
 
 out:
+  gtk_combo_box_update_sensitivity (combo_box);
+
   g_object_notify (G_OBJECT (combo_box), "model");
 }
 
@@ -5670,6 +5732,55 @@ gtk_combo_box_set_row_separator_func (GtkComboBox                 *combo_box,
   gtk_widget_queue_draw (GTK_WIDGET (combo_box));
 }
 
+/**
+ * gtk_combo_box_set_button_sensitivity:
+ * @combo_box: a #GtkComboBox
+ * @sensitivity: specify the sensitivity of the dropdown button
+ *
+ * Sets whether the dropdown button of the combo box should be
+ * always sensitive (%GTK_SENSITIVITY_ON), never sensitive (%GTK_SENSITIVITY_OFF)
+ * or only if there is at least one item to display (%GTK_SENSITIVITY_AUTO).
+ *
+ * Since: 2.14
+ **/
+void
+gtk_combo_box_set_button_sensitivity (GtkComboBox        *combo_box,
+                                      GtkSensitivityType  sensitivity)
+{
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+
+  if (combo_box->priv->button_sensitivity != sensitivity)
+    {
+      combo_box->priv->button_sensitivity = sensitivity;
+      gtk_combo_box_update_sensitivity (combo_box);
+
+      g_object_notify (G_OBJECT (combo_box), "button-sensitivity");
+    }
+}
+
+/**
+ * gtk_combo_box_get_button_sensitivity:
+ * @combo_box: a #GtkComboBox
+ *
+ * Returns whether the combo box sets the dropdown button
+ * sensitive or not when there are no items in the model.
+ *
+ * Return Value: %GTK_SENSITIVITY_ON if the dropdown button
+ *    is sensitive when the model is empty, %GTK_SENSITIVITY_OFF
+ *    if the button is always insensitive or
+ *    %GTK_SENSITIVITY_AUTO if it is only sensitive as long as
+ *    the model has one item to be selected.
+ *
+ * Since: 2.14
+ **/
+GtkSensitivityType
+gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box)
+{
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
+
+  return combo_box->priv->button_sensitivity;
+}
+
 
 /**
  * gtk_combo_box_set_focus_on_click:
index cc93415a0cb5a0d5af00016abceb1c7e99b197e8..1da1562b1992e4c6a9b5d242addb41ea2cbcecda 100644 (file)
@@ -114,6 +114,10 @@ void                        gtk_combo_box_set_row_separator_func (GtkComboBox
                                                                  gpointer                    data,
                                                                  GDestroyNotify              destroy);
 
+void               gtk_combo_box_set_button_sensitivity (GtkComboBox        *combo_box,
+                                                        GtkSensitivityType  sensitivity);
+GtkSensitivityType gtk_combo_box_get_button_sensitivity (GtkComboBox        *combo_box);
+
 /* convenience -- text */
 GtkWidget    *gtk_combo_box_new_text         (void);
 void          gtk_combo_box_append_text      (GtkComboBox     *combo_box,